package com.exam.api.modules.classInfo.controller.manager;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.exam.api.common.web.TinyResponse;
import com.exam.api.modules.classInfo.domain.TblClassNumberInfo;
import com.exam.api.modules.classInfo.dto.ClassPageDto;
import com.exam.api.modules.classInfo.service.TblClassNumberInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * (管理端) 试卷主表相关接口
 */
@Tag(name = "(管理端) 试卷主表相关接口", description = "(管理端) 试卷主表相关接口")
@RestController
@RequestMapping("/manager/classNumberInfo")
@TinyResponse
public class TblClassNumberInfoManagerController {

    @Resource
    private TblClassNumberInfoService tblClassNumberInfoService;

    @Operation(summary = "创建", description = "创建试卷")
    @PostMapping("/save")
    public Long saveExamPaper(@RequestBody TblClassNumberInfo dto) {
        tblClassNumberInfoService.saveOrUpdate(dto);
        return dto.getId();
    }

    @Operation(summary = "分页查询", description = "分页查询")
    @PostMapping("/page")
    public IPage<TblClassNumberInfo> page(@RequestBody ClassPageDto dto) {
        QueryWrapper<TblClassNumberInfo> query = new QueryWrapper<>();
        query.lambda().eq(TblClassNumberInfo::getIsDelete, 0);
        query.lambda().orderByDesc(TblClassNumberInfo::getCreateTime);
        return tblClassNumberInfoService.page(dto.buildPage(), query);
    }

    @Operation(summary = "修改", description = "修改试卷")
    @PostMapping("/update")
    public void updateTblExamPaper(@RequestBody TblClassNumberInfo tblExamPaper) {
        tblClassNumberInfoService.updateById(tblExamPaper);
    }

    @Operation(summary = "删除", description = "删除试卷")
    @PostMapping("/delete/{id}")
    public void deleteTblExamPaper(@PathVariable("id") Long id) {
        tblClassNumberInfoService.removeById(id);
    }

    @Operation(summary = "根据ID获取试卷题目", description = "根据ID获取试卷题目")
    @PostMapping("/{id}")
    public TblClassNumberInfo getTblExamPaper(@PathVariable("id") Long id) {
        return tblClassNumberInfoService.getById(id);
    }
}